package com.lyc.mapper;

import com.lyc.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //根据用户名查询用户
    @Select("select * from users where username = #{username}")
    User findByUserName(String username);

    //添加用户
    @Insert("insert into users(username,password_hash,created_at,updated_at) " +
            "values(#{username},#{md5String},now(),now())")
    void add(String username, String md5String);

    //更新用户信息
    @Update("update users set display_name = #{displayName},email = #{email}," +
            "phone = #{phone},gender = #{gender},role = #{role},bio = #{bio} where username = #{username}")
    void updateUserInfo(User user);

    //更新用户密码
    @Update("update users set password_hash = #{md5String} where username = #{username}")
    void updatePassword(String md5String, String username);
}
